import java.util.*;

public class GameOfLifeDivTwo {
	public String theSimulation(String init, int T) {
		int state[] = new int [init.length()];
        for (int i = 0; i  < init.length(); ++i){
                state[i] = init.charAt(i) - '0';
        }
        int prev[] = new int[state.length];
        for (int t = 1; t <= T; ++t){
            System.arraycopy(state, 0, prev, 0, state.length);
            for (int i = 0; i < state.length; ++i){
                int cur = i, cur1 = (i + 1) % state.length, cur2 = (i + 2) % state.length;
                state[cur1] = prev[cur] + prev[cur1] + prev[cur2] > 1 ? 1 : 0;
            }
        }
        StringBuilder res = new StringBuilder();
        for (int current : state){
            res.append(current);
        }
        return res.toString();
	}
}
